<?php
/**
 * Created by xiaosong
 * E-mail:4155433@gmail.com
 * Date: 2019/10/25
 * Time: 11:47
 */

namespace App\Services\banner;


use App\Models\banner\Banner;
use App\Models\banner\BannerCate;
use App\Models\config\Config;
use Illuminate\Database\Eloquent\Collection;

class BannerService
{

    public function getModel():Banner
    {
        return new Banner();
    }

    public function getCate():array
    {
        return array_pluck(BannerCate::select('id','cate_name')->get()->toArray(), 'cate_name','id');
    }

    public function getBanner(int $cid,int $num):Collection
    {
        $map['status'] = 1;
        $map['cid']    = $cid;
        return $this->getModel()
            ->select('title','url','img','type')
            ->orderBy('sort')
            ->where($map)
            ->limit($num)
            ->get();
    }

}